// 左Y轴设置
import React, { useState } from 'react';
import { Switch, Input } from 'antd';
import Editor from 'src/pages/AnalyseManage/EditReport/components/EditorStyleType/Editor';
import FormItem from 'antd/lib/form/FormItem';

interface IProps {
	config: any;
	onValuesChange: ( chartType: string, key: string, values: Object, configType: string ) => void;
	form: any;
}

const RYAxis = ( props: IProps ) => {
	const { config, onValuesChange, form } = props;

	const fontConfig = [ 'fontFamily', 'fontSize', 'fontColor', 'fontBold', 'fontItalic' ];

	// const { isShowRYLine, isShowRYLineName } = config.style;

	const [ isShowRYLine, setIsShowRYLine ] = useState(
		config.style && config.style.hasOwnProperty( 'isShowRYLine' ) ? config.style.isShowRYLine : true
	);
	const [ isShowRYLineName, setIsShowRYLineName ] = useState(
		config.style && config.style.hasOwnProperty( 'isShowRYLineName' ) ? config.style.isShowRYLineName : false
	);

	const onChange = ( checked: boolean, name: string, cb: any ) => {
		cb && cb();
		form.setFieldsValue( { [name]: checked } );
		onValuesChange( config.type, config.key, { [name]: checked }, 'style' );
	};

	const onBlur = ( value: any, name: string ) => {
		onValuesChange( config.type, config.key, { [name]: form.getFieldsValue()[name] }, 'style' );
	};

	return (
		<div>
			<FormItem
				label="是否显示轴线"
				name="isShowRYLine"
				labelAlign="left"
				labelCol={{ span: 8 }}
				wrapperCol={{ span: 16 }}
			>
				<Switch
					checked={isShowRYLine}
					onChange={( checked ) => onChange( checked, 'isShowRYLine', setIsShowRYLine( checked ) )}
				></Switch>
			</FormItem>
			{isShowRYLine && (
				<>
					<FormItem
						label="是否显示轴名称"
						name="isShowRYLineName"
						labelAlign="left"
						labelCol={{ span: 8 }}
						wrapperCol={{ span: 16 }}
					>
						<Switch
							checked={isShowRYLineName}
							onChange={( checked ) => onChange( checked, 'isShowRYLineName', setIsShowRYLineName( checked ) )}
						></Switch>
					</FormItem>

					{isShowRYLineName && (
						<>
							<FormItem label="Y轴名称" name="chartRYAxisName">
								<Input
									onBlur={( value ) => onBlur( value, 'chartRYAxisName' )}
									onPressEnter={( value ) => onBlur( value, 'chartRYAxisName' )}
								></Input>
							</FormItem>
							<FormItem
								label="字体"
								name="chartRYLineFont"
								labelAlign="left"
								labelCol={{ span: 8 }}
								wrapperCol={{ span: 16 }}
							>
								<Editor
									config={config}
									form={form}
									onValuesChange={onValuesChange}
									fontFamilyName="RYLineFontFamily"
									fontSizeName="RYLineFontSize"
									fontColorName="RYLineFontColor"
									boldName="RYLineFontBold"
									italicName="RYLineFontItalic"
									fontConfig={fontConfig}
								/>
							</FormItem>
						</>
					)}
				</>
			)}
			{/* <FormItem
				label="数据单位"
				name="chartRYAxisDataUnit"
				labelAlign="left"
				labelCol={{ span: 8 }}
				wrapperCol={{ span: 16 }}
			>
				<Select allowClear>
					<Select.Option value="percent">%</Select.Option>
					<Select.Option value="tenthousand">万</Select.Option>
					<Select.Option value="million">百万</Select.Option>
				</Select>
			</FormItem> */}
		</div>
	);
};

export default React.memo( RYAxis );
